#include "window_common.h"

enum {
	WIDGET_ID_TITLE = 0,
	WIDGET_ID_LIST,
	WIDGET_ID_MAX
};

static const gkt_widget_list_item_s sc_window_time_setting_widget_list_items[] = {
	GKT_WIDGET_LIST_STATIC_ITEM(WINDOW_TEXT_ID_system_time, 
			WINDOW_ID_system_time_setting),
	GKT_WIDGET_LIST_STATIC_ITEM(WINDOW_TEXT_ID_auto_close_time, 
			WINDOW_ID_lock_auto_close_time),
#if defined(GKT_CONFIG_DOOR_LOCK_AUTOMATIC) && GKT_CONFIG_DOOR_LOCK_AUTOMATIC
	GKT_WIDGET_LIST_STATIC_ITEM(WINDOW_TEXT_ID_auto_double_close_time,
			WINDOW_ID_lock_auto_double_close_time),
#endif
#if (GKT_USER_GUEST_MAXNUMS > 0)
	GKT_WIDGET_LIST_STATIC_ITEM(WINDOW_TEXT_ID_guest_unlock_time, 
			WINDOW_ID_guest_unlock_time_setting),
#endif
};
static const gkt_widget_list_attr_s sc_window_time_setting_widget_list_attr = 
	GKT_WIDGET_LIST_STATIC_ATTR(WINDOW_WIDGET_NORMAL_HEIGHT,
		sizeof(sc_window_time_setting_widget_list_items) / sizeof(gkt_widget_list_item_s),
		sc_window_time_setting_widget_list_items);

GKT_WINDOW_WIDGET_DESCS_DEFINE(time_setting) = {
	[WIDGET_ID_TITLE] = GKT_WIDGET_LABEL_DESC( 
		GKT_WIDGET_F_ALIGN_MIDDLE | GKT_WIDGET_F_TITLE_MARK,
		WINDOW_FONT_NORMAL_SIZE, 
		WINDOW_TITLE_FG_COLOR, WINDOW_TITLE_BG_COLOR,
		0, 0, 
		WINDOW_WIDGET_DEFAULT_WIDTH, WINDOW_WIDGET_NORMAL_HEIGHT,
		WINDOW_TEXT_ID_time_setting
	),
	[WIDGET_ID_LIST] = GKT_WIDGET_LIST_DESC(
		GKT_WIDGET_F_ALIGN_MIDDLE,
		WINDOW_FONT_NORMAL_SIZE, 
		WINDOW_DEFAULT_FG_COLOR, WINDOW_DEFAULT_BG_COLOR,
		0, WINDOW_WIDGET_NORMAL_HEIGHT, 
		WINDOW_WIDGET_DEFAULT_WIDTH, WINDOW_WIDGET_NORMAL_HEIGHT * (WINDOW_NORMAL_ROWS - 1),
		&sc_window_time_setting_widget_list_attr
	),
};

static int window_time_setting_event_handler(
				uint32_t major_type, uint32_t minor_type, 
				uint32_t widget_id, uint32_t data)
{
	int retval = GKT_EVENT_HANDLE_CONTINUE;
	gkt_window_id_t window_id;

	switch (major_type) {
		case GKT_EVENT_WINDOW:
			if(minor_type == GKT_WINDOW_ACTIVE)
				window_common_mask_except_updn_cancel_ok();
			break;
		case GKT_EVENT_WIDGET:
			if(minor_type == GKT_WIDGET_EVENT_CLICK) {
				window_id = (gkt_window_id_t)sc_window_time_setting_widget_list_items[data].data;
				gkt_window_show(window_id, 0);
				retval = GKT_EVENT_HANDLE_COMPLETE;
			}
			break;						
		default:
			break;
	}
	
	return retval;
}
GKT_WINDOW_DESC_DEFINE(time_setting);

